﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using OOS.Application.Cart.Dtos;
using OOS.Application.Cart.Services.Interfaces;
using OOS.Core.Cart;

namespace OOS.Application.Cart
{
    /// <summary>
    /// 购物车
    /// </summary>
    [Route("[Controller]")]
    public class ShoppingCartAppService:IDynamicApiController
    {
        private readonly IShoppingCartService _shoppingCartService;

        public ShoppingCartAppService(IShoppingCartService shoppingCartService)
        {
            _shoppingCartService = shoppingCartService;
        }

        /// <summary>
        /// 新增购物车数据并返回购物车数据id
        /// </summary>
        /// <param name="shoppingCart"></param>
        /// <returns></returns>
        [HttpPost]
        public int AddShoppingCart(ShoppingCart shoppingCart)
        {
            return _shoppingCartService.InsertShoppingCart(shoppingCart);
        }

        /// <summary>
        /// 根据id查询购物车数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ShoppingCartDto GetShoppingCart(int id)
        {
            return _shoppingCartService.SelectShoppingCartById(id);
        }

        /// <summary>
        /// 通过token中的用户id获取对应的购物车列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<ShoppingCartDto> GetCartList()
        {
            return _shoppingCartService.SelectShoppingCartDtosByUserId();
        }

        /// <summary>
        /// 根据id修改对应购物车数据
        /// </summary>
        /// <param name="shoppingCart"></param>
        /// <returns></returns>
        [HttpPut]
        public Boolean UpdateShoppingCart(ShoppingCart shoppingCart)
        {
            return _shoppingCartService.UpdateShoppingCartById(shoppingCart);
        }

        /// <summary>
        /// 根据id列表批量删除购物车数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public Boolean DeleteCartList([FromBody]int[] ids)
        {
            return _shoppingCartService.DeleteShoppingCartByIds(ids);
        }
    }
}
